package com.huang.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huang.dao.PetBlogMapper;
import com.huang.entity.PetBlog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.List;

@Controller
@ResponseBody
public class PetBlogController {
    @Autowired
    PetBlogMapper petBlogMapper;

    @GetMapping("/petBlog/querryAll")
    public List<PetBlog> querryAll(){
        List<PetBlog> petBlogs = petBlogMapper.querryAll();
        return petBlogs;
    }
    @GetMapping("/petBlog/querryAll/{current}/{size}")
    public IPage<String> querryAll(@PathVariable("current") Integer current,
                                   @PathVariable("size") Integer size){
        Page<PetBlog> page = new Page<>(current, size);
        IPage<String> stringIPage = petBlogMapper.selectMyPetBlog(page);
        return stringIPage;
    }
    @GetMapping("/petBlog/querryById/{id}")
    public PetBlog querryById(@PathVariable("id") Integer id){
        PetBlog petBlog = petBlogMapper.querryById(id);
        return petBlog;
    }
    @PostMapping("/petBlog/insertPetBlog")
    public String insertPetBlog(@RequestBody PetBlog petBlog){
        int i = petBlogMapper.insertPetBlog(petBlog);
        if (i>0){
            return "success";
        }else {
            return "error";
        }
    }
}
